package com.ruoyi.web.controller.shouhou;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.ShouhouFanxin;
import com.ruoyi.system.domain.ShouhouInfo;
import com.ruoyi.system.service.IEpmShouhouRecoditionService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 售后翻新controller
 */


@RestController
@RequestMapping("/Empment/shouhou")
public class EpmShouhouReconditionController extends BaseController {
    @Autowired
    private IEpmShouhouRecoditionService iEpmShouhouRecoditionService;

    /**
     * 查询翻新信息表
     */
    @PreAuthorize("@ss.hasPermi('Empment:recondition:list')")
    @GetMapping("/recondition/list")
    public TableDataInfo list(ShouhouFanxin shouhouFanxin) {
        startPage();
        List<ShouhouFanxin> list = iEpmShouhouRecoditionService.list(shouhouFanxin);
        return getDataTable(list);
    }


    /**
     * 新增数据
     */
    @PreAuthorize("@ss.hasPermi('Empment:recondition:insert')")
    @PostMapping("/recondition/insert")
    public AjaxResult insert(@RequestBody ShouhouFanxin shouhouFanxin){
        iEpmShouhouRecoditionService.insertFanxinInfo(shouhouFanxin);
        return AjaxResult.success();
    }


    /**
     *  修改数据
     */
    @PreAuthorize("@ss.hasPermi('Empment:recondition:update')")
    @PutMapping("recondition/update")
    public AjaxResult update(@RequestBody ShouhouFanxin shouhouFanxin){
        iEpmShouhouRecoditionService.update(shouhouFanxin);
        return AjaxResult.success();
    }


    /**
     *  翻新操作
     */
    @PreAuthorize("@ss.hasPermi('Empment:recondition:fanxin')")
    @PutMapping("recondition/fanxin")
    public AjaxResult shouhouFanxin(@RequestBody  ShouhouFanxin shouhouFanxin){
        if(!Objects.equals(shouhouFanxin.getOldSnId(), shouhouFanxin.getNewSnId())) {
            System.out.println(shouhouFanxin);
            iEpmShouhouRecoditionService.shouhouFanxin(shouhouFanxin);
            return AjaxResult.success();
        }else{
            return AjaxResult.error("新SN码与原SN码相同");
        }
    }


    /**
     * 入库
     */
    @PreAuthorize("@ss.hasPermi('Empment:recondition:ruku')")
    @DeleteMapping("recondition/ruku")
    public AjaxResult fanxinRuku(@RequestBody  ShouhouFanxin shouhouFanxin) {
        iEpmShouhouRecoditionService .fanxinRuku(shouhouFanxin);
        return AjaxResult.success();
    }
}
